package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.LoginService;

@RestController
@RequestMapping("/api/login")
public class LoginController {

    private LoginService loginService;

    @Autowired
    public void autowiredService(LoginService loginService){
        this.loginService = loginService;
    }

    @RequestMapping("/user")
    public Result userLogin(@RequestParam long code, @RequestParam String password,
                            HttpServletRequest request, HttpServletResponse response){
        return loginService.userLogin(code, password, request, response);
    }

    @RequestMapping("/admin")
    public Result adminLogin(@RequestParam String username, @RequestParam String password,
                            HttpServletRequest request, HttpServletResponse response){
        return loginService.adminLogin(username, password, request, response);
    }

}
